{extends file="../home.html"}
{block name="title"}{$head_title}{/block}
{block name="css"}
<!-- <link rel="stylesheet" style="text/css" href="__PUBLIC__/Css/front/user_glb.css?version={$version}"> -->

<style type="text/css">
   input[type="date"]:before{
        content: attr(placeholder);
    } 
    #date{
        background-color:transparent;
    }
    body{
    	padding-top:2.2rem;
    }
</style>
{/block}
{block name="content"}
<div class="service_header">
    <i class="icon icon_back_default3x mui-action-back" onclick="onlyBack();" style="top:.7rem"></i>
    <span  onclick="onlyBack();">返回</span>
    <p>预约入驻</p>
</div>
<form>
<ul class="visit_from">
    <li class="clearfix">
        <label for="yin" class="fl">拟入驻园区</label>
        <input type="text" id="yin" name="incubator_name"  value="{$incubator_info.incubator_name}" readonly>
    </li>
    <li class="clearfix">
        <label for="date" class="fl">预约时间</label>
        <input type="date" id="date" name="order_time" value="" placeholder="请选择预约时间">
        <i class="fr icon icon_enter_default3x"></i>
    </li>
    {if $is_park!=1}
    <li class="clearfix">
        <label for="date" class="fl">预约天数</label>
        <input type="number" name="day_num" value="" placeholder="最小入驻天数为30天">
    </li>
    {/if}
    <li class="clearfix">
        <label for="name" class="fl">公司/项目名称</label>
        <input type="text" id="name" name="company_name" value="" placeholder="请输入公司/项目名称">
    </li>
    <li class="clearfix">
        <label for="name_ren" class="fl">联系人姓名</label>
        <input type="text" id="name_ren" name="contacts" value="" placeholder="请输入预约人姓名">
    </li>
    <li class="clearfix">
        <label for="tell" class="fl">联系人电话</label>
        <input type="number" id="tell" name="contact_number" value="" placeholder="请输入联系人电话">
    </li>

    {if $is_park!=1}
    <li class="clearfix">
        <label for="number" class="fl">工位数量</label>
      <!--  <select name="" id="number">
            <option value="请选择参观人数">请选择参观人数</option>
        </select>-->
        <input type="number" id="number" name="station_num" value="" placeholder="请输入工位数量">
    </li>
  
    <li class="clearfix">
        <label for="station_type" class="fl">工位类型</label>
        <select name="station_class" id="station_class">
            <option value="0">请选择工位类型</option>
            {foreach from=$incubator_list item=incubator}
            <option value="{$incubator.station_class_id}">{$incubator.class_name}</option>
            {/foreach}
        </select>
        <i class="fr icon icon_enter_default3x"></i>
    </li>
    <!-- <li class="clearfix">
        <label for="station_type" class="fl">工位类型</label>
        <select name="station_type" id="station_type">
            <option value="0">请选择工位类型</option>
            {foreach from=$incubator_list item=incubator}
            <option value="{$incubator.station_type_id}">{$incubator.station_type_name}</option>
            {/foreach}
        </select>
        <i class="fr icon icon_enter_default3x"></i>
    </li> -->
    {else}
    <li class="clearfix">
        <label for="number" class="fl">预约面积</label>
        <!--  <select name="" id="number">
              <option value="请选择参观人数">请选择参观人数</option>
          </select>-->
        <input type="hidden" value="0" name="station_type">
        <input type="number"  name="station_num" value="" placeholder="请输入预约面积">
    </li>

    {/if}
    <input type="hidden" value="order" name="opt">
    <input type="hidden" value="{$incubator_id}" name="incubator_id">
    <input type="hidden" value="{$type}" name="type">
</ul>
<h6 class="bei">备注</h6>
<textarea name="user_remarks" placeholder="请输入备注" class="bei_txt"></textarea>
    <h6 class="bei">上传商业计划书</h6>
    
    <div class="up_img clearfix preview-recom">
        {if $is_ios == 0}
        <div class="up_img_box fl">
            <a href="javascript:;" class="add icon fl icon_upload_default3x" title="上传一张新的图片" id="add_upload"></a>
            <!--<input type="hidden" name="prospectus_url" class="img_url" id="img_url" />-->
        </div>
        <input type="hidden" name='cover'>
        <div class="preview fl clearfix img_html"></div>
        {else}
        请将商业计划书发送邮件至{$service_email}
        {/if}
    </div>

</form>
<div class="submit_btn">提交</div>
{/block}
{block name="js"}
<script>
    incubator_id={$incubator_id}
    var is_ios = parseInt('{$is_ios}')
</script>

<script type="text/javascript" src="/Public/Js/front/front_js/ajaxupload.3.5.js"></script>
        <script type="text/javascript">
            
        {literal}
        function is_ios() {
    		    var browserName = navigator.userAgent.toLowerCase();
    		    return /(iphone|ipod|ipad)/i.test(browserName);
    		}
        	function onlyBack(){
        		var _json = JSON.stringify({
		            event: 'back'
		        });
        		if(!is_wechat()){
        			if (is_ios()) {
			            return window.webkit.messageHandlers.webviewEvent.postMessage(_json);
			        } else {
			            return ResultAndroid.webviewEvent(_json);
			        }
				}else{
					history.go(-1);
				}
        	}
            
              
            
            $(function()
            {
             /*   $(".service_header i,.service_header span").on("click",function()
                {
                    history.go(-1);
                    //window.location='/FrontIncubator/park_detail/incubator_id/'+incubator_id;
                });*/
                $(".submit_btn").on("click",function()
                {
                    if($("#yin").val()=='')
                    {
                        layer.open({
                            content: '请输入预约园区',
                            title: false,
                            btn: ['确定'],
                        });
                        return;
                    }
                    if($('[name=day_num]').val() == '' || parseInt($('[name=day_num]').val()) < 30){
                      layer.open({
                            content: '预约入驻天数必须大于30天',
                            title: false,
                            btn: ['确定'],
                        });
                        return;
                    }
                    if($("#name").val()=='')
                    {
                        layer.open({
                            content: '请输入公司/项目名称',
                            title: false,
                            btn: ['确定'],
                        });
                        return;
                    }
                    if($("#name_ren").val()=='')
                    {
                        layer.open({
                            content: '请输入预约人姓名',
                            title: false,
                            btn: ['确定'],
                        });
                        return;
                    }
                    if($("#tell").val()=='')
                    {
                        layer.open({
                            content: '请输入联系人电话',
                            title: false,
                            btn: ['确定'],
                        });
                        return;
                    }
                    $.ajax({
                        type: 'POST',
                        url: '/FrontIncubator/order_park_enter' ,
                        data: $('form').serialize(),
                        dataType:'json',
                        success:function(data) {
                            console.log(data)
                            if(data.code == 1 ){
                                layer.open({
                                    content:data.msg,
                                    title: false,
                                    btn: ['确定'],
                                    yes:function(){
                                        if(!is_wechat()){
                                            var dataUrl = '/FrontIncubator/order_zhongchuang_detail/order_id/'+data.order_id;
                                            var _json = JSON.stringify({
                                                event: "to_jump",
                                                params: {"url":dataUrl}
                                            });
                                            if(is_ios()){
                                                window.webkit.messageHandlers.webviewEvent.postMessage(_json);
                                            }else{
                                                window.ResultAndroid.webviewEvent(_json);
                                            }
                                        }else{
                                            location.href = '/FrontIncubator/order_zhongchuang_detail/order_id/'+data.order_id;
                                        }
                                    }
                                });
                               //location.href ="/FrontIncubator/park_detail/incubator_id/"+incubator_id;
                            }else if(data.code == 2){
                              layer.open({
                                    content:data.msg,
                                    title: false,
                                    btn: ['确定'],
                                    yes:function(){
                                       if(!is_wechat()){
                                           native_listen('back');
                                       }else{
                                           history.go(-1);
                                       }
                                    }
                              })
                            }else{
                                layer.open({
                                    content:data.msg,
                                    title: false,
                                    btn: ['确定'],
                                });
                            }
                        }
                    })

                });
            });
			/*$("#date").focus(function(){
				$(this).removeAttr("placeholder")
			});
			$("#date").blur(function(){
				if($("#date").val()==""){
					$(this).setAttr("placeholder","请选择预约时间");	
				}
			});*/
            //date的placeholder兼容方案
            var i_date = document.getElementById('date');
		    i_date.onfocus = function(){
		        this.removeAttribute('placeholder');
		    };
		    i_date.onblur = function(){
		        if(this.value == '') this.setAttribute('placeholder','请选择预约时间');
		    };



        new AjaxUpload("#add_upload", {
                  action: "/Front/uploadFileHandler",
                  name: "upfile",
                  responseType: "json",
                  onSubmit: function(){
                      //alert('正在上传');
                      //preview处的图片改为loading图片
                      $('.preview-recom').show();
                      /*if($("#upload-recom").siblings('.preview-recom').find('img').length>=3){
                       alert("最多上传3张图片");
                       return false;
                       }*/
                  },
                  onChange: function(file, extension){
                      if (extension&&/^(doc|docx|pdf|xls|xlsx|txt)$/.test(extension)) {
                          return true;
                      }
                      else {
                          //alert('暂不支持该文件格式！');
                          layer.open({
                              content: '暂不支持该文件格式',
                              title: false,
                              btn: ['确定'],
                          });
                          return false;
                      }
                  },
                  onComplete: function(file, response){
                      if (response.status === 0) {
                         console.log(11);
                      }else if (response.status === 1) {
                          console.log('success');
                          var html;
                          html='<div class=" fl img_box"><img class="pic-preview" src="/Public/Images/front/front_img/word.png" /><div class="del_img"></div></div>';
                          $('.preview-recom').prepend(html);
                          // $("#add_upload").siblings('.preview').show();
                          //$("#img_url_recom").val(1);
                          //删除图片
                          $(".del_img").on("click",function(){
                              if($(this).parents(".preview").find('img').length==1){
                                  console.log(1);
                                  $(this).parents(".img_html_recom").siblings('.img_url_recom').val('');
                              }
                              $(this).parent(".img_box").remove();
                              $('.preview-recom').find('.up_img_box').show();
                          });

                          $('input[name=cover]').val(response.img_url);
                          $('.preview-recom').find('.up_img_box').hide();
                      }
                  }
              });
        </script>
{/literal}
{/block}